<template>
    <div class="container">
        <el-row class="wrap-search">
            <el-button @click="" type="primary" size="medium" @click="$router.push('/ruleEdit')">新增规则</el-button>
        </el-row>
        <el-row class="wrap-search">
            <div class="search-item">
                <div class="search-title">标题：</div>
                <el-input style="width: 200px;" class=""
                          placeholder="请输入标题"
                          v-model="configList.param.title" ></el-input>
            </div>
            <el-button  class="search-btn" type="primary" @click="getList()">查询</el-button>
        </el-row>
        <div class="">
            <table-list ref="tableList" :tableConfig='configList' @selectTable="selectTable">
                <el-table-column
                        slot="select"  align="center" label="全选"
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column slot="image"  align="center" label="用户头像">
                    <template slot-scope="scope">
                        <img class="video-img" :src="scope.row.avatarUrl" alt="">
                    </template>
                </el-table-column>
                <el-table-column class="btn"  label="操作" slot="btn" align="center" >
                    <template slot-scope="scope">
                        <el-button  class="search-btn" size="small" type="primary" @click="$router.push('/ruleEdit?id='+scope.row.id+'&title='+scope.row.title)">查看</el-button>
                         <el-button class="search-btn" size="small" type="danger" @click="delLevel(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </table-list>
        </div>
        <el-dialog
                :visible.sync="dialogVisible"
                size="tiny"
        >
            <img :src="imgUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
    let CONSTANT = require('../../constant/constant.js');
    let common = require("../../common.js");
    export default {
        data() {
            return {
                configList:{
                    url:CONSTANT.URL.RULE.LIST,
                    configList:[
                        {
                            label:'标题',
                            prop:'title'
                        },
                        {
                            label:'内容',
                            prop:'content'
                        },
                        {
                            label:'添加时间',
                            prop:'gmtCreated'
                        },
                        {
                            slot:'btn'
                        }
                    ],
                    param:{
                        title: ""
                    },
                    type:'',
                    width:'',
                    isPagination:true
                },
                dialogVisible:false,
                dialogVisible1:false,
                imgUrl:'',
                upLoadUrl:'',
                dataList:[],
                provinceList:[],
                cityList:[],
                ids: []
            }
        },
        components: {
            'table-list':() => import('../common/my-table')
        },
        watch:{
            'configList.param.provinceCode':function(val){
                this.cityList = [];
                this.configList.param.cityCode  = ''
                this.getCityList()
            }
        },
        created(){

        },
        mounted() {

        },
        methods: {
            getList(){
                this.$refs.tableList.getList()
            },
            imgClick(url){
                this.imgUrl = url;
                this.dialogVisible = true;
            },
            showPage(id){
                this.dialogVisible1 = true;
                this.getNums(id)
            },
            hotBtn(id,state){
                let  url = CONSTANT.URL.CAR.SAVEHOT,
                    dataForm = {},
                    data = {
                        isHot:state?'':1,
                        id:id
                    };
                common.requestAjax(url,JSON.stringify(data),dataForm,(res)=>{
                    if(res.status == 200){
                        this.$message({
                            type: 'success',
                            message:res.msg
                        });
                        this.getList();
                    }else{
                        this.$message({
                            message: res.msg,
                            type: 'warning'
                        });
                    }
                })
            },
            delLevel(id){
                this.$confirm('确定删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let  url = CONSTANT.URL.RULE.DELETE,
                        param = {id: id}
                    common.requestAjax(url,{},param,(res)=>{
                        if(res.status == 200){
                            this.$message({
                                type: 'success',
                                message:res.msg
                            });
                            this.getList();
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'warning'
                            });
                        }
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            selectTable(val) {
                console.log(val)
                this.ids = []
                val.map( item => {
                    this.ids.push(item.id)
                })
            },
            delAll() {
                if (!this.ids.length) {
                    this.$message({
                        type: 'warning',
                        message: '请选择批量删除的记录'
                    });
                    return false;
                }
                this.$confirm('确定删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let url = CONSTANT.URL.USERCORE.DELETES;
                    common.requestAjax(url, {}, {ids: this.ids}, (res) => {
                        if(res.status == 200){
                            this.$message({
                                type: 'success',
                                message:res.msg
                            });
                            this.getList();
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'warning'
                            });
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    }
</script>

<style lang="scss">
    .container {
        .wrap-search{
            margin-bottom: 20px;
            .search-item{
                float: left;
                margin-right: 20px;
                margin-top: 20px;
                .el-input,.el-select{
                    width: 180px;
                }
            }
            button{
                float: left;
                margin-top: 20px;
            }
            .search-title{
                display: inline;
                width: 100px;
                height: 36px;
                line-height: 36px;
                text-align: right;
                margin-bottom: 20px;
                margin-right: 10px;
            }
        }
        .el-table__row{
            .cell{
                button{
                    margin-top: 10px;
                }
            }
            video{
                width: 100px;height: auto;
            }
            img.video-img{
                width: 60px;height: 60px;
                cursor: pointer;
                border-radius: 30px;
            }
        }
        .pagination {
            text-align: center;
            width: 80%;
            margin-top: 60px;
        }
        .el-dialog__body{
            img{
                display: block;
                margin: 0 auto;
            }
        }
        .user-num{
            color:#409EFF;
            cursor: pointer;
        }

        .avatar{
            width: 50px!important;
            height: 50px;
            border-radius: 50%;
            -webkit-border-radius: 50%;
        }
    }
</style>
